<template>
  <div :class="['number-card', { 'number-card-clickable': clickable, 'number-card__round': round }]">
    <div :class="['number-card-inner', { 'grey-line': greyLine }]">
      <template v-if="horizon">
        <div style="font-size: 18px">
          <i v-if="icon" :class="[icon ? icon : '', 'number-icon']"></i>
          <div class="number-card-info">
            <p class="number-card_label" :style="{ fontSize: labelFontSize }">{{ title }}：</p>
            <p class="number-card-number" :style="{ color: numColor }">{{ number }}</p>
          </div>
          <span class="number-card_label sub-title" :style="{ fontSize: labelFontSize }">{{ subTitle }}</span>
        </div>
      </template>
      <template v-else>
        <p :style="[{ fontSize: numberFontSize }, { color: numColor }]" class="number-card-number">{{ number }}</p>
        <p class="number-card_label" :style="{ fontSize: labelFontSize }">{{ title }}</p>
      </template>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'NumberCard',
    props: {
      horizon: Boolean,
      clickable: Boolean,
      round: Boolean,
      number: {
        type: [Number, String],
        default: 0
      },
      numberFontSize: {
        type: String,
        default: '20px'
      },
      labelFontSize: {
        type: String,
        default: '14px'
      },
      numColor: {
        type: String,
        default: '#ef6666'
      },
      title: {
        type: String,
        default: ''
      },
      subTitle: {
        type: String,
        default: ''
      },
      greyLine: Boolean,
      icon: {
        type: String,
        default: ''
      }
    }
  }
</script>

<style lang="scss">
  .number-card {
    @include flex-column;
    align-items: center;
    justify-content: center;
    padding: 10px;

    &.number-card__round {
      .number-card-inner {
        border-radius: 50%;
      }
    }

    &.number-card-clickable {
      cursor: pointer;

      .number-card-number {
        // text-decoration: underline;
      }

      .number-card-inner {
        position: relative;
        top: 0;
        transition: top 0.3s;

        &:hover {
          top: -10px;
          box-shadow: 0 2px 5px var(--theme-shadow);

          .number-card-number {
            text-decoration: underline;
          }
        }
      }
    }

    .grey-line {
      border-left: 4px solid #e0e2e8;
    }

    .number-card-number {
      font-weight: bold;
      font-size: 18px;
    }

    .number-card_label {
      color: #898989;

      // display: inline-block;
      // width: 75px;
      // text-align: end;
    }

    .number-card-inner {
      @include flex-column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      background-color: #fff;
      border-radius: 4px;
      box-shadow: 0 1px 4px 0 #e0e2e8;
    }

    .number-card-info {
      display: flex;
      align-items: center;
      width: 100%;

      .number-card_label {
        width: 90px;
        text-align: right;
      }

      .number-card-number {
        flex: 1;
        width: 120px;
      }
    }

    .number-icon {
      position: absolute;
      top: 0;
      left: 0;
      width: 40px;
      height: 100%;
      margin-right: 10px;
      padding: 10px;
      color: #ef6666;
      vertical-align: -2px;
      background: #fff3f3;
      border-radius: 4px 0 0 4px;
    }

    .sub-title {
      position: absolute;
      top: 50%;
      right: 10px;
      transform: translate(0, -50%);
    }
  }
</style>
